{extends file="../global.html"}
{block name=body}

<div class="content" >
  <!-- 右侧内容框架，更改从这里开始 -->
  <form class="layui-form xbs" action="{url('/run/type/index')}" method="get">
      <div class="layui-form-pane" style="text-align: center;">
        <div class="layui-form-item" style="display: inline-block;">
          <!-- <label class="layui-form-label xbs768">日期范围</label>
          <div class="layui-input-inline xbs768">
            <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
          </div>
          <div class="layui-input-inline xbs768">
            <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
          </div> -->
          <div class="layui-input-inline">
            <input type="text" name="type_name"  placeholder="请输入车系名" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-input-inline" style="width:80px">
              <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
          </div>
        </div>
      </div> 
  </form>
  <xblock><span class="x-right" style="line-height:40px">共有数据： 条</span></xblock>
  <table class="layui-table">
      <thead>
          <tr>
             
              
              <th>
                 网站标题
              </th>
              <th>
                  网站log
              </th>
              <th>
                 网站关键字(多个关键字用<span style="color: red">英文逗号</span>隔开)
              </th>

              <th>
                 网站描述
              </th>
              <th>
				         网站状态
              </th>
          </tr>
      </thead>
      <tbody>
     
          <tr class="car_{$res.website_id}">
         
              
              <td class="website_title"> {$res.website_title}</td>
                
          
              <td class="website_log">
                  <!-- <img src="" alt="">  -->
                   <div id="result" clss="website_log"><img  width="36" src="{$absroot}{$res.website_log}" alt=""></div>  
                  <form id="form1" clss="website_log">  
                   
                      <input type="button" clss="website_log" value="上传图片" onclick="f.click()" class="layui-btn layui-btn-normal "/><br>  
                     <p><input type="file" id="f" name="pic" onchange="sc(this);" style="display:none"/></p>  
                  </form>  
                 
              </td>
      				<td class="website_keywords">{$res.website_keywords}</td>
				     <td class="website_description">{$res.website_description}</td>
               <td class="td-status">           
                <span va="{$res.website_state}" class="layui-btn {if $res.website_state==1} layui-btn-normal {else} layui-btn-danger {/if}layui-btn-mini show-{$res.website_id}" onclick="show({$res.website_id})">{if $res.website_state == 0}维护中{else}开启{/if}</span>          
              </td>
            
          </tr>
       
      </tbody>
      

  </table>
  <script type="text/javascript">
      
      function sc(id){    
        var form = $('#form1')[0];
        // console.log(form);
        var data = new FormData(form);   
        // console.log(data);
        $.ajax({    
            url: "{url('run/website/pic')}",   
            type: 'POST',    
            data: data, 
            fileElementId:'f',
            dataType: 'JSON',    
            cache: true,
            processData: false,    
            contentType: false    
        }).done(function(ret){ 

          // console.log(ret);return;  
            if(ret['isSuccess'] == '图片上传过大,请重新上传'){  
                 layer.msg('上传失败,图片上传过大,请重新上传');  
            }else if(ret['isSuccess'] == '没有图片上传'){  
                  layer.msg('没有图片上传');
            }else if(ret['isSuccess'] == '只有部分文件上传'){ 
                  layer.msg('只有部分文件上传');
            }else{

               
                var result = '';  
                var result1 = '';  
                // $("#show").attr('value',+ ret['f'] +);  
                result += '<img src="{$absroot}' + ret['f']  + '" width="100">';  
                // result1 += '<input value="' + ret['f']  + '" name="user_headimg" style="display:none;">';  
                $('#result').html();  
                $('#result').html(result);  
                // $('#show').html(result1);  
                layer.msg('上传成功');  
            }    
        });    
        return false;    
    }  

    var td = $('.car_1').find('td');
    for(var i= 0;i<=td.length-1;i++){
     var tdDemo = td[i];
     // console.log(tdDemo.className);
      // alert($(this).attr('class'));
       if(tdDemo.className != 'website_log' && tdDemo.className != 'td-status'){
      $(td[i]).click(function(){
        
       
          // alert(1);
           var cla = $(this).attr('class');
           var v = $(this).text();
            //    //获取当前事件作用对象的文本值
            // var v=$(this).html();
            //清楚td的文本值
            $(this).empty();
            //创建input
            // var input=$('<input type="text" style="width:120px;color:#222">');
            var input=$('<textarea rows="8" cols="40" style="color:#222"></textarea>');
            //把创建好的input元素内部插入到td
            $(this).append(input);
            //获取焦点事件
            input.focus();
            //在获取焦点时给input赋值
            input.val(v);
            //使处于选中
            input.select();
            var td=$(this);
            // //绑定失去焦点事件
            input.blur(function(){
            //   //获取当前数据的id
              var id=$(this).parents("tr").find("td:first").html();
            //   //获取当前元素的value值
              var newV=$(this).val();
              //var newC=$(this).parents('td').attr('id');

              // console.log($(this).parent("td").html());

              // Ajax
             $.ajax({
                      type:"post",
                      data:{ id:id,newV:newV,cla:cla},
                      url:"{url('run/website/ajaxUpdate')}",
                                success:function(msg){
                                    
                                    if(msg==true){
                                        alert('修改成功');
                                         
                                    }
                                  
                                 },
                                 error:function(){
                                        
                                }

                             })
               $(this).parent("td").html(newV);
              $(this).remove();     
                            })
             



       
      })
   }
    }
    function show(id){
      // alert(id);
      var cla = 'website_state';
     var  v = $('.td-status').find('.show-'+id).attr('va');
     if(v == 1){
        v = 0;
     }else{
        v = 1;
     }
     $.ajax({
         type:"post",
         data:{ id:id,newV:v,cla:cla},
         url:"{url('run/website/ajaxUpdate')}",
          success:function(msg){
                  // alert(msg);
                  if(msg==true){
                    if(v == 0){
                      // alert(v);
                      // alert(1);
                         $('.td-status').find('.show-'+id).removeClass('layui-btn-normal').addClass('layui-btn-danger').text('维护中').attr('va',0);
                          
                    }else{
                      // alert(2);
                      $('.td-status').find('.show-'+id).removeClass('layui-btn-danger').addClass('layui-btn-normal').text('开启').attr('va',1);
                     
                    }
                       
                  }
                
               },
     })
    }
  </script>
{/block}